#include "Geometry.h"
#include "Shader.h"
#include "Texture.h"
#include "graphics/GLState.h"
#include <Preprocessor.h>
#include <memory>
namespace Umikaze::Core {

class SkyBox {

  CORE_OBJECT
public:
  static void drawSkyBox(const std::shared_ptr<Texture> &texture,
                         const glm::mat4 &viewMatrix,
                         const glm::mat4 &projMatrix) {
    static std::unique_ptr<Shader> skyBoxShader =
        std::make_unique<Shader>("DrawSkyBox.vert", "DrawSkyBox.frag");
    static std::unique_ptr<Geometry> skyBoxGeometry =
        std::make_unique<CubeGeometry>(2, 2, 2);

    auto cubeTexture = std::dynamic_pointer_cast<CubeTexture>(texture);
    if (cubeTexture) {
      skyBoxShader->setCondition("USE_CUBEMAP", true);
    } else {
      //使用等距柱状投影图
      skyBoxShader->setCondition("USE_CUBEMAP", false);
    }

    skyBoxShader->bind();

    skyBoxShader->setMat4("viewMatrix", viewMatrix);
    skyBoxShader->setMat4("projMatrix", projMatrix);

    skyBoxShader->setTexture("skybox", texture);

    skyBoxGeometry->draw();
  }
};

} // namespace Umikaze::Core